<template>
  <div class="search">
    <div class="top">
      <div v-if="this.username==null"><mt-button style="float:right" type="default" @click="onSubmit1">登录></mt-button></div>
      <div v-if="this.username!=null"><mt-button style="float:right" type="default" @click="loginout">注销></mt-button></div>
    <br/><br/><br/>
    <div class="img">
        <img src="../../img/menu16.png" min-width="70" height="70"/>
    </div>
    <div class="userName" v-for="item in tableData" :key="item.id">
        <span class="userName" s>{{item.trueName}}</span>
    </div>
    <br/>
    </div>
    <div>
      <img src="../../img/全部订单.png" @click="onSubmit3" min-width="60" height="60"/>
    </div>
    <!-- 中间 -->
    <div>
    <div style="border-bottom:3px solid #E7E8E9">
       <img src="../../img/待付款.png" @click="onSubmit8" min-width="65" height="65"/>&nbsp;&nbsp;&nbsp;
          <img src="../../img/待发货.png" @click="onSubmit12" min-width="65" height="65"/>&nbsp;&nbsp;&nbsp;
       <img src="../../img/待收货.png" @click="onSubmit13" min-width="65" height="65"/>&nbsp;
       <img src="../../img/已完成.png" @click="onSubmit11" min-width="65" height="65"/>
    </div>
    <br />
    <div style="border-bottom:3px solid #E7E8E9">
      <img src="../../img/待使用.png" @click="onSubmit5" min-width="65" height="65"/>&nbsp;&nbsp;&nbsp;&nbsp;
      <img src="../../img/已使用.png" @click="onSubmit6" min-width="65" height="65"/>&nbsp;&nbsp;&nbsp;
      <img src="../../img/过期使用.png" @click="onSubmit7" min-width="65" height="65"/>
    </div>
    <div class="goods-list">
      <div>
         <img  style="border-bottom:2px solid #E7E8E9" src="../../img/收货地址.png" @click="onSubmit2" min-width="48.7" height="48.7"/>
      </div>
      <div>
       <img  style="border-bottom:2px solid #E7E8E9" src="../../img/服务中心.png" @click="onSubmit4" min-width="50" height="50"/>
       </div>
      <div>
        <img  style="border-bottom:2px solid #E7E8E9" src="../../img/我的收藏.png" @click="onSubmit10" min-width="47.5" height="47.5"/>
      </div>
    </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "about",
  data() {
    return {
      tableData: [],
      username:localStorage.getItem('username')
    };
  },
  created() {
    if(this.username!=null){
      this.getUser();
    }
  },
  methods: {
    onSubmit10(){
      this.$router.push("/ad");
    },
    onSubmit7(){
      this.$router.push("/Coupon2");
    },
    onSubmit6(){
      this.$router.push("/Coupon1");
    },
    onSubmit4(){
       this.$router.push("/Issue");
    },
    onSubmit5(){
      if(localStorage.getItem('username')==null){
        alert("亲，请先登录哦");
        this.$router.push('/login')
        return
      }
      this.$router.push('/Coupon')
    },
    onSubmit3(){
      if(localStorage.getItem('username')==null){
        alert("亲，请先登录哦");
        this.$router.push('/login')
        return
      }
      this.$router.push('/Order')
    },
     onSubmit11(){
      if(localStorage.getItem('username')==null){
        alert("亲，请先登录哦");
        this.$router.push('/login')
        return
      }
      this.$router.push('/Order')
    },
     onSubmit8(){
      if(localStorage.getItem('username')==null){
        alert("亲，请先登录哦");
        this.$router.push('/login')
        return
      }
      var status=0;
      this.$router.push('/Order/'+status);
    },
       onSubmit12(){
      if(localStorage.getItem('username')==null){
        alert("亲，请先登录哦");
        this.$router.push('/login')
        return
      }
      var status=1;
      this.$router.push('/Order/'+status);
    },
       onSubmit13(){
      if(localStorage.getItem('username')==null){
        alert("亲，请先登录哦");
        this.$router.push('/login')
        return
      }
      var status=2;
      this.$router.push('/Order/'+status);
    },
    onSubmit2(){
      if(localStorage.getItem('username')==null){
        alert("亲，请先登录哦");
        this.$router.push('/login')
        return
      }
      this.$router.push('/Address')
    },
    onSubmit1(){
      this.$router.push('/login')
    },
    loginout(){
      this.$messagebox({
          title: '温馨提示',
          message: '确认要注销吗?',
          showCancelButton: true,
          confirmButtonText:"确认",
          cancelButtonText:"取消"
        }).then(action => {
          if(action == 'confirm'){
            console.log('退出');
            localStorage.removeItem("username");
            location.reload();
          }else{
            console.log('取消');
          }
      })
    },
    getUser() {
      var $this = this;
      this.axios({
        method: "get",
        url: "http://localhost:9999/system/ecUser/userList",
        params:{userName:this.username}
      }).then(function(res) {
        console.log("查询列表返回的数据为:{}", res);
        $this.tableData = res.data.obj.list;
        localStorage.setItem("userId",res.data.obj.list[0].id);
      });
    }
  }
};
</script>
<style scoped>
  .top {
    background-color:#FEDFEF;
  }
  .img{
    padding-left: 165px;
  }
  .userName{
    padding-left: 84px;
    font-size: 20px;
  }
</style>
